package org.changchen.fgt.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.commons.lang.StringUtils;

/**   
* @ClassName:  BgmDateUtil   
* @Description:BgmList 网时间转换   
* @author:     ChangChen 
* @date:       2024-02-02 08:57
* @Copyright:  2024 ChangChen. All rights reserved. 
*/
public class BgmDateUtil {
	
	
	/**   
	 * @Title:      parse   
	 * @Description:UTC时间字符串Date   
	 * @param:      @param dateStr
	 * @param:      @return      
	 * @return:     Date      
	 * @throws   
	 */
	public static Date parse(String dateStr) {
		
		if(StringUtils.isBlank(dateStr)) {
			dateStr = "2023-01-01T00:00:00.000Z";
		}
		
		dateStr = dateStr.replace("Z", " UTC");
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
		try {
		    return format.parse(dateStr);
		} catch (Exception e) {
		    e.printStackTrace();
		}
		
		return null;
	}
	
		
	/**   
	 * @Title:      week   
	 * @Description:星期几/周几   
	 * @param:      @param date
	 * @param:      @return      
	 * @return:     String      
	 * @throws   
	 */
	public static String week(Date date, boolean zhou) {
		SimpleDateFormat sdf = new SimpleDateFormat("E", Locale.CHINA);
		String week = sdf.format(date);
		if(zhou) {
			return week.replace("星期", "周");
		}
		return week;
	}
	
	
	/**   
	 * @Title:      beginDate   
	 * @Description:开始日期   
	 * @param:      @param date
	 * @param:      @return      
	 * @return:     String      
	 * @throws   
	 */
	public static String beginDate(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(date);
	}
	
	
	/**   
	 * @Title:      time   
	 * @Description:   
	 * @param:      @param date
	 * @param:      @return      
	 * @return:     String      
	 * @throws   
	 */
	public static String time(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
		return sdf.format(date);
	}
	
	
	/**   
	 * @Title:      isNew   
	 * @Description:是否是本季新番   
	 * @param:      @param date
	 * @param:      @return      
	 * @return:     Boolean      
	 * @throws   
	 */
	public static Boolean isNew(Date date) {
	    Long starTime=date.getTime();
	    Long endTime=new Date().getTime();
	    Long num=endTime-starTime;//时间戳相差的毫秒数
	    return (num/24/60/60/1000) < 90;//除以一天的毫秒数

	}
	
	
	private BgmDateUtil() {}
	
}
